
/***************************************************************************
 *   Copyright (C) 2009 by Bernhard Neuhofer                               *
 *   mail@bneu.at   							   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef __MESSAGE_H
#define __MESSAGE_H

#include "interpreter.h"
using namespace std;

/**
*@brief Abstract root class of all messages
*/
class Message
{
	private:
//Stores the timestamp of the message
		double _timestamp;

//The receiver of this message
		unsigned int _receiver;

//Wether it is a poditive- of an antimessage
		bool _sign;

//The Color of the message (used for the GVT algo). white ==true
		bool _color;

	public:
		/**
		* Constructs a positiv or antimessage with the given sign, timestamp, receiver and color.
		* @param sign The sign of the message
		* @param timestamp The timestamp of the message
		* @param receiver The receiver of the message
		* @param color The color of the message
		*/
		Message ( bool sign, double timestamp, unsigned int receiver,bool color ) : _sign(sign),_timestamp(timestamp),_receiver(receiver),_color(color)
		{

		}
		/*
		Constructs a positiv or antimessage with the given sign, timestamp and color. The receiver is initialised with zero and changed when the message is sent.
		@param sign The sign of the message
		@param timestamp The timestamp of the message
		@param color The color of the message
		*/
		Message ( bool sign,double timestamp, bool color ) :_sign(sign),_timestamp(timestamp),_receiver(0),_color(color)
		{}

		/**
		* Constructs a positiv message with the given timestamp, receiver and color.
		* @param timestamp The timestamp of the message
		* @param receiver The receiver of the message
		* @param color The color of the message
		*/
		Message ( double timestamp,unsigned int receiver, bool color ): _sign(true),_timestamp(timestamp),_receiver(receiver),_color(color)
		{}

		/**
		* Constructs a positiv message with the given  timestamp and color.
		* @param timestamp The timestamp of the message
		* @param color The color of the message
		*/
		Message ( double timestamp,bool color ): _sign(true),_timestamp(timestamp),_receiver(0),_color(color)
		{}

		/**
		Constructs a positiv or antimessage with the given sign, timestamp, receiver and default color.
		@param sign The sign of the message
		@param timestamp The timestamp of the message
		@param receiver The receiver of the message
		*/
		Message ( bool sign,double timestamp,unsigned int receiver ): _sign(sign),_timestamp(timestamp),_receiver(receiver),_color(true)
		{}

		/**
		Constructs a positiv or antimessage with the given sign, timestamp, receiver and default color. The receiver is initialised with zero and changed when the message is sent.
		@param sign The sign of the message
		@param timestamp The timestamp of the message
		*/
		Message ( bool sign,double timestamp ): _sign(sign),_timestamp(timestamp),_receiver(0),_color(true)
		{}

		/**
		* Constructs a positiv message with the given timestamp, receiver and default color.
		* @param timestamp The timestamp of the message
		* @param receiver The receiver of the message
		*/
		Message ( double timestamp,unsigned int receiver ): _sign(true),_timestamp(timestamp),_receiver(receiver),_color(true)
		{}

		/**
		* Constructs a positiv message with the given timestamp.
		* @param timestamp The timestamp of the message
		*/
		Message ( double timestamp ): _sign(true),_timestamp(timestamp),_receiver(0),_color(true)
		{}

		/**
		* Abstract! Checks if a model entity is able to interpret the message and calls the corresponding <code>execute</code> method of the ME if so.This is a command-pattern, see GoF p233
		* @param message The message to interpret
		*/
		virtual void interpret ( Interpreter* intpr) =0;

		/**
		* Creates a antimessage to the message. This is a kind of factory method.
		* @return dual the associated antimessage
		*/
		virtual Message* createDual() =0;
		/**
		* Returns the sign of the message
		* @return bool sign of the message
		*/
		virtual bool isPositive();

		/**
		 * Returns the timestamp of the message
		 * @return double timestamp of the message
		 */
		virtual double getTimestamp();

		/**
		 * Returns the receiver of the message.
		 * @return int receiver of the message
		 */
		virtual unsigned int getreceiver() const;

		/**
		 * Returns the color of the message
		 * @return bool
		 */
		virtual bool getColor();

		/**
		 * Sets the sign
		 * @param sign The sign to set
		 */
		virtual void setSign ( bool sign );
		/**
		 * Sets the timestamp of the message (must be positive)
		 * @param timestamp the timestamp to set
		 */
		virtual void setTimestamp ( double timestamp );

		/**
		 * Sets the receiver of the message
		 * @param receiver the id of the receiver LP
		 */
		virtual void setReceiver ( int receiver );

		/**
		 * Sets the color
		 * @param color Sets the color to the given Value (white==true)
		 */
		virtual void setColor ( bool color );

		/**
		 * Compare operator: Tests if ttwo messages are equal. If a subclass defines additional attributes it has to overwrite the <code>operator==</code> method and provide a adequate comparison.
		 * @param other The message to compare to
		 * @return Returns true if the messages are equal
		 */
		 virtual  bool operator== ( const Message &other ) const;
};

#endif // __MESSAGE_H
